#coding:utf-8
'''
* coder  : dzlua
* email  : 505544956@qq.com
* module : api-frame
* path   : app
* file   : mgr.py
* time   : 2017-11-07 16:21:04
'''
#--------------------#
from flask import Flask, Blueprint
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_restful import Api
from flask_auth_mgr import AuthMgr
from flask_mail import Mail
#----------#
import config
#----------#
from app.utils.response import makeResponse, R404_NOTFOUND
#----------#
from app.utils import base
#--------------------#

#--------------------#
class SelfApi(Api):
    def handle_error(self, e):
        resp = Api.handle_error(self, e)
        data = base.json_load(resp.data)
        status = { 'code': resp.status_code, 'message': data['message'] }
        resp.data = base.json_dump({ 'status': status }) + '\n'
        return resp
#--------------------#

#--------------------#
app = Flask(__name__)
app.config.from_object(config)
#
manager = Manager(app)
#
db = SQLAlchemy(app)
#
migrate = Migrate(app, db)
#
auth = AuthMgr(app.config['SECRET_KEY'])
#
mail = Mail(app)
#
apibp = Blueprint('api', __name__, url_prefix='/api')
api = SelfApi(apibp, catch_all_404s=True)
app.register_blueprint(apibp)
#--------------------#
